<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/global.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

			<form class="layui-form form-container" lay-filter="scoreRuleForm" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">问题</label>
					<div class="layui-input-block">
						<input type="text" name="question" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">

					</div>
				</div>

				<div class="layui-form-item">

					<!--<div class="layui-inline">
						<label class="layui-form-label">巡查日期：</label>
						<div class="layui-input-inline">
							<input type="text" id="startPatrolTime" name="startPatrolTime"
								   readonly="" class="layui-input" placeholder="请选择">
						</div>
					</div>-->

					<div class="layui-inline">
						<label class="layui-form-label">巡察单位</label>
						<div class="layui-input-inline">
							<select name="brancha" lay-filter="brancha" id="brancha">
							</select>
						</div>
					</div>

					<div class="layui-inline">
						<label class="layui-form-label">部门</label>
						<div class="layui-input-inline">
							<select name="branchb" lay-filter="branchb" id="branchb">
							</select>
						</div>
					</div>

					<div class="layui-inline">
						<label class="layui-form-label">督察形式</label>
						<div class="layui-input-inline">
							<select name="overseeForm" id="overseeForm" lay-verify="required" lay-filter="xmFilter">
								<option value=""></option>
							</select>
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">问题类别</label>
						<div class="layui-input-inline">
							<select name="questionType" id="questionType" lay-verify="required" lay-filter="xmFilter">
								<option value=""></option>
							</select>
						</div>
					</div>

					<div class="layui-inline">
						<label class="layui-form-label">问题关键字</label>
						<div class="layui-input-inline">
							<select name="questionKeyword" id="questionKeyword" lay-verify="required" lay-filter="xmFilter">
								<option value=""></option>
							</select>
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label" >问题描述</label>
					<div class="layui-input-block" >
						<textarea placeholder="请输入内容" class="layui-textarea"></textarea>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-block">
						<textarea placeholder="请输入内容" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn save" lay-submit lay-filter="saveBtn">提交</button>

						<button type="button" class="layui-btn save2" lay-filter="saveBtn2">转至草稿箱</button>

						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>

            </div>

        </div>
    </div>

	<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<!--<script src="../../layui/laydate/laydate.js"></script>-->
	<script type="text/javascript" src="../../js/my/permission.js"></script>
	<script type="text/javascript">
		//获取url后的参数值
		function getUrlParam(key) {
			var href = window.location.href;
			var url = href.split("?");
			if(url.length <= 1){
				return "";
			}
			var params = url[1].split("&");

			for(var i=0; i<params.length; i++){
				var param = params[i].split("=");
				if(key == param[0]){
					return param[1];
				}
			}
		}

		// 数据回显
		layui.use(['layer','form'], function(){
			var layer = layui.layer;
			var form = layui.form;
			var id = getUrlParam("id");
			console.log(id);
			if(id > 0){
				$.ajax({
					type : 'get',
					url : '/mOverseeQuestions/'+id,
					async : false,
					success : function(data) {
						//console.log(data)
						form.val('scoreRuleForm',{
							"question": data.question,
							"questionId": data.questionId,
							"questionType": data.questionType,
							"questionKeyword": data.questionKeyword,
							"questionDetail": data.questionDetail,
							"remark": data.remark,
							"overseeForm": data.overseeForm,
							"brancha": data.brancha,
							"branchb": data.branchb,
							"startPatrolTime": data.startPatrolTime,
						})
					}

				});
			}

		});



		// 下拉框可能会用到 New option
		// 这个里面的参数说明 第一个是显示的文本，第二个是value值
		// 例如：new Option(item.xm, item.id)第一个参数是下拉列表中显示的值  第二个参数是选中传递给后台的值
		layui.use(['form', 'upload', 'layer'],function(){
			var form = layui.form;
			$.ajax({
				url: '/mOverseeForms/getList',
				dataType: 'json',
				type: 'post',
				success: function (data) {
					//console.log(data);// 下面会提到这个data是什么值
					// 使用循环遍历，给下拉列表赋值
					$.each(data, function (index, value) {
						// console.log(value.department_id);
						$('#overseeForm').append(new Option(value.overseeStatus,value.id));// 下拉菜单里添加元素
					});
					layui.form.render("select");//重新渲染 固定写法
				}
			})

		});
		layui.use(['form', 'upload', 'layer'],function(){
			var form = layui.form;
			$.ajax({
				url: '/mQuestionKeywords/getList',
				dataType: 'json',
				type: 'post',
				success: function (data) {
					//console.log(data);// 下面会提到这个data是什么值
					// 使用循环遍历，给下拉列表赋值
					$.each(data, function (index, value) {
						// console.log(value.department_id);
						$('#questionKeyword').append(new Option(value.questionKeyword,value.id));// 下拉菜单里添加元素
					});
					layui.form.render("select");//重新渲染 固定写法
				}
			})
		});
		layui.use(['form', 'upload', 'layer'],function(){
			var form = layui.form;
			$.ajax({
				url: '/mQuestions/getList',
				dataType: 'json',
				type: 'post',
				success: function (data) {
					//console.log(data);// 下面会提到这个data是什么值
					// 使用循环遍历，给下拉列表赋值
					$.each(data, function (index, value) {
						// console.log(value.department_id);
						$('#questionType').append(new Option(value.question,value.id));// 下拉菜单里添加元素
					});
					layui.form.render("select");//重新渲染 固定写法
				}
			})
		});
		layui.use(['layer', 'form','jquery'], function () {
			var $= layui.jquery;
			var form = layui.form;
			//如果有加载页面就渲染第一个一级分类的话 就先调用一次方法
			renderSelect($('#brancha'));
			//监听一级分类下拉框变化
			form.on('select(brancha)',function(res){
				//变化就渲染第二个分类   把第一个下拉框的value传递
				renderSelect($('#branchb'),res.value);
			});
			function renderSelect(ele,id){
				//先判断id是否有值,这里是为了第一个下拉框改变值的时候 好把第二个下拉框的选项都删掉
				if(id){
					//ele.length = 0;
					ele.empty()
				}
				$.ajax({
					url: '/mBranchs/getBranchs',
					dataType: 'json',
					type: 'post',
					data: {brandId:id},
					success: function (data) {
						//console.log(data);// 下面会提到这个data是什么值
						// 使用循环遍历，给下拉列表赋值
						data.forEach((item,index)=>{
							var option = new Option(item.branchName,item.id);
							ele.append(option);
						});
						layui.form.render("select");//重新渲染 固定写法
					}
				})
			}
		});
		layui.use(['form','laydate'], function(){
			var  form = layui.form ;
			$ = layui.jquery ;
			laydate = layui.laydate;

			laydate.render({     //创建时间选择框
				elem: '#startPatrolTime'//指定元素
				,btns: ['confirm']
				,theme: 'grid'
				,trigger: 'click'
			});

		});
		//监听提交

		layui.use(['form'], function () {
			var form = layui.form,
					layer = layui.layer,
					$ = layui.$;
			var id = getUrlParam("id");
			//监听提交
			form.on('submit(saveBtn)', function (data) {
				// 单击之后提交按钮不可选,防止重复提交
				var DISABLED = 'layui-btn-disabled';
				// 增加样式
				$('.save').addClass(DISABLED);
				// 增加属性
				$('.save').attr('disabled', 'disabled');
				data.field.questionId = id;
				data.field.brancha = $("#brancha option:selected").text();//获取文本 id: 以降序排列此列
				data.field.branchb = $("#branchb option:selected").text();//获取文本
				data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
				data.field.questionType = $("#questionType option:selected").text();//获取文本
				data.field.overseeForm = $("#overseeForm option:selected").text();//获取文本
				//console.log(JSON.stringify(data.field));

				$.ajax({
					type : 'POST',
					dataType: 'json',
					url : '/mOverseeQuestions/updateQuestion',
					contentType: "application/json; charset=utf-8",
					data : JSON.stringify(data.field),
					success : function (res) {
						//console.log(res);
						if(res.errorCode == 0){
							location.href = "mOverseeQuestionList.html";
						}else {
							layer.msg(res.errorMsg);
						}

					}
				})
				return false;

			});





		});





	</script>
</body>
</html>



